#include "RingQueue.hpp"
#include <iostream>
#include <unistd.h>

void *producer(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);

    int data = 1;
    while(true)
    {
        sleep(1);
        std::cout<<"我是一个生产者, 我生产了一个数据: "<<data<<std::endl;

        data++;
    }
}

void *consumer(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);

    int data;
    while(true)
    {
        rq->Pop(&data);
        std::cout<<"我是一个消费者, 我消费了一个数据: "<<data<<std::endl;
    }
}

int main()
{
    pthread_t c, p;
    RingQueue<int> *rq = new RingQueue<int>();

    int n1 = pthread_create(&p, nullptr, producer, (void *)rq);
    int n2 = pthread_create(&c, nullptr, consumer, (void *)rq);

    int r1 = pthread_join(p, nullptr);
    int r2 = pthread_join(c, nullptr);
    return 0;
}